<template>
  <div class="detaile">
      <div class="title">
        <i class="iconfont iconzuojiantou" @click="onClickLeft"></i>
        <span>{{tite}}</span>
        <i class="iconfont iconzuojiantou" style="color: white;"></i>
    </div>
    <div class="content">
        <div class="content-BOX"  v-html="dataa">
          {{dataa}}
        </div>
    </div>
  </div>
</template>

<script>
  export default {
      name:'detaile',
      data (){
        return {
           type:"",
           tite:"",
           dataa:"",

            vid:"",
            villageName:'请输入所在村庄',//村庄
            name:"",//名字
            codeNum:"",//身份证号
            urlImg:"",
            urlImgOne:"",
            urlImgTwo:"",
            term:"",
            code:true,
            code1:true,
            code2:true,
            pathUrl:"",
        }
      },
      created (){
          this.type = this.$route.query.type;
          this.tite = this.$route.query.value;
          this.pathUrl = this.$route.query.url;
          this.vid = this.$route.query.vid;
          this.villageName = this.$route.query.villageName;
          this.name = this.$route.query.name;
          this.codeNum = this.$route.query.codeNum;
          this.urlImg = this.$route.query.urlImg;
          this.urlImgOne = this.$route.query.urlImgOne;
          this.urlImgTwo = this.$route.query.urlImgTwo;
          this.term = this.$route.query.term;
          this.PostAxios();

           // 监听浏览器返回
        if (window.history && window.history.pushState) {
            history.pushState(null, null, document.URL);
            window.addEventListener('popstate', this.goBack, false);
        }
      },
       destroyed(){
        // 销毁监听浏览器事件
        window.removeEventListener('popstate', this.goBack, false);
     },
      methods:{
        onClickLeft (){
          if(this.urlImgTwo == "" || this.urlImgTwo == undefined){
            this.code2 = true
            console.log("this.code",this.code2)
          }
          if(this.term == false){
            this.$router.push({
              path:"/Autonym",
              query:{
                vid:this.vid,
                villageName:this.villageName,
                name:this.name,
                codeNum:this.codeNum,
                urlImg:this.urlImg,
                urlImgOne:this.urlImgOne,
                urlImgTwo:this.urlImgTwo,
                theme:"实名认证",
                code:this.code,
                code1:this.code1,
                code2:this.code2,
                Seurl:false,
                url: this.pathUrl,
              }
            });
          }
          else{
             this.$router.go(-1)
          }
        },
        PostAxios(){
            this.$axios.post("/cct/text/list",{
                type:this.type
            }).then(res =>{
                console.log("文本",res)
                if(res.data.code == 0){

                    this.dataa=res.data.rows[0].content
                    // console.log("标签",this.dataa)
                   let informationArticle = informationArticle.replace(/<\/?(img)[^>]*>/gi, '');
                   const regex = new RegExp('<img', 'gi')
                    res.details = details.replace(regex, `<img style="max-width: 100%; height: auto"`);
                }
                
            })
        },
        goBack(){
            if(this.urlImgTwo == "" || this.urlImgTwo == undefined){
                this.code2 = true
                console.log("this.code",this.code2)
            }
            if(this.term == false){
                this.$router.push({
                path:"/Autonym",
                query:{
                    vid:this.vid,
                    villageName:this.villageName,
                    name:this.name,
                    codeNum:this.codeNum,
                    urlImg:this.urlImg,
                    urlImgOne:this.urlImgOne,
                    urlImgTwo:this.urlImgTwo,
                    theme:"实名认证",
                    code:this.code,
                    code1:this.code1,
                    code2:this.code2,
                    Seurl:false,
                    url: this.pathUrl,
                }
                });
            }
            else{
                this.$router.go(-1)
            }
            //replace替换原路由，作用是避免回退死循环
        }
    }
  }
</script>

<style lang="less" scoped>
.detaile{
    width: 100%;
    height: 100%;
    background-color: #f8f8f8;
    font-size: 0;
    .title{
        width: 100%;
        font-size: 0.36rem;
        color:#333;
        height: 1.25rem;
        line-height: 1.25rem;
        background-color: #fff;
        margin-bottom: 0.2rem;
        display: flex;
        justify-content: space-between;
        padding: 0 0.2rem;
        box-sizing: border-box;
    }
    .content{
        font-size: 0.26rem;
        margin-top:0.2rem;
        background-color: #fff;
        padding: 0.4rem 0.3rem 0.4rem 0.4rem;
        // box-sizing: border-box;
        .content-BOX{
            width: 100%;
            div{
              max-width: 100% !important;
              img{
                max-width:7rem !important;
              }
            }
        }
    }
}
</style>
